## AdoptOpenJDK 停止发布 OpenJDK 二进制，而 Eclipse Temurin 是它的延伸，提供更好的稳定性
FROM eclipse-temurin:21-jre

WORKDIR /popjoy

## 设置 TZ 时区 TZ=Asia/Shanghai
ENV TZ=UTC

RUN mkdir -p /popjoy && mkdir -p /var/log/popjoy && mkdir -p /popjoy/heapdump && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo$TZ > /etc/timezone

COPY ./target/app.jar /popjoy/app.jar

RUN chmod 555 /popjoy/app.jar

# 设置 JAVA_OPTS_EXTRA 环境变量追加
ENV JAVA_OPTS_EXTRA=""
# 设置 JAVA_OPTS 环境变量，可通过 docker run -e "JAVA_OPTS=" 进行覆盖
ENV JAVA_OPTS=" -XX:InitialRAMPercentage=75.0 -XX:MaxRAMPercentage=75.0 -XX:HeapDumpPath=/popjoy/heapdump/heapdump.hprof -Xlog:gc*,heap*,age*,safepoint=debug:file=/var/log/popjoy/gc.log:time,uptime,level,tags:filecount=10,filesize=10M -XX:+ParallelRefProcEnabled -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTLAB -XX:+PerfDisableSharedMem -XX:+UseStringDeduplication -XX:+UseCondCardMark -XX:+ExitOnOutOfMemoryError -XX:+HeapDumpOnError -XX:+HeapDumpOnOutOfMemoryError -XX:+IgnoreUnrecognizedVMOptions"

## 应用参数
ENV ARGS="-Duser.timezone=UTC --server.port=8080  --management.server.port=18080"

EXPOSE 8080 18080

CMD java ${JAVA_OPTS} ${JAVA_OPTS_EXTRA} -jar /popjoy/app.jar $ARGS